﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.Modules.Version.AdminSource
{
    public partial class _edit : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //通过ccid传频道ID
            ChannelId = Str2Str(q("ccid"));
            id = Str2Str(q("id"));
            Admin_Load(ChannelId + "-04", "html", true);
            if (!Page.IsPostBack)
            {
                this.ddlSortId.Items.Clear();
                this.ddlSortId.Items.Add(new ListItem("不指定任何类别", "0"));
                doh.Reset();
                doh.SqlCmd = "SELECT [ID],[Title] FROM [jcms_module_version_source_sort] WHERE [ChannelId]=" + ChannelId + " ORDER BY Id ASC";
                DataTable dtSort = doh.GetDataTable();
                for (int i = 0; i < dtSort.Rows.Count; i++)
                {
                    this.ddlSortId.Items.Add(new ListItem(dtSort.Rows[i]["Title"].ToString(), dtSort.Rows[i]["Id"].ToString()));
                }
                dtSort.Clear();
                dtSort.Dispose();
            }
            doh.Reset();
            string _nowtime = Jumbot.Common.staticFunction.GetNow("time");
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_module_version_source", btnSave);
            wh.AddBind(ddlSortId, "SortId", false);
            wh.AddBind(txtTitle2, "Title2", true);
            wh.AddBind(txtAuthor2, "Author2", true);
            wh.AddBind(txtAuthorSummary2, "AuthorSummary2", true);
            wh.AddBind(txtSourceFrom2, "SourceFrom2", true);
            wh.AddBind(txtSourceFromUrl2, "SourceFromUrl2", true);
            wh.AddBind(txtWordCount2, "WordCount2", true);
            wh.AddBind(txtRemark, "Remark", true);
            wh.AddBind(ref _nowtime, "AddDate", true);
            wh.AddBind(txtDownUrl2, "DownUrl2", true);
            if (id == "0")
                wh.Mode = Jumbot.DataOper.OperationType.Add;
            else
            {
                wh.ConditionExpress = "id=" + id;
                wh.Mode = Jumbot.DataOper.OperationType.Modify;
            }
            wh.BindBeforeModifyOk += new EventHandler(bind_ok);
            wh.AddOk += new EventHandler(add_ok);
            wh.ModifyOk += new EventHandler(save_ok);
            wh.validator = chkForm;
        }
        /// <summary>
        /// 绑定数据后的处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void bind_ok(object sender, EventArgs e)
        {
            this.txtAuthorSummary2.Text = Jumbot.Common.Strings.HtmlDecode(this.txtAuthorSummary2.Text);
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            return true;
        }
        protected void add_ok(object sender, EventArgs e)
        {
            Jumbot.DataOper.DbOperEventArgs de = (Jumbot.DataOper.DbOperEventArgs)e;
            id = de.id.ToString();
            doh.Reset();
            doh.ConditionExpress = "id=@id";
            doh.AddConditionParameter("@id", id);
            doh.AddFieldItem("ArmsId", 0);
            doh.AddFieldItem("State", 0);
            doh.AddFieldItem("IsLocked", 1);
            doh.AddFieldItem("UserId", 0);
            doh.AddFieldItem("ChannelId", ChannelId);
            doh.Update("jcms_module_version_source");
            FinalMessage("成功添加", site.Dir + "admin/close.htm", 0);
        }
        protected void save_ok(object sender, EventArgs e)
        {
            FinalMessage("成功修改", site.Dir + "admin/close.htm", 0);
        }
        /// <summary>
        /// 点击提交按钮后的一些操作
        /// 此事件是在数据正式入库前完成的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.txtAuthorSummary2.Text = GetCutString(Jumbot.Common.Strings.HtmlEncode(this.txtAuthorSummary2.Text), 1000);
        }
    }
}
